<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.mobile }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email }}</div>
              </li>

              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="anq" /> 安全设置
                <div  class="pull-right">
                  <a  style="color: #13ce66" @click="$refs.pass.dialog = true">修改密码</a>
                </div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <!--    操作日志    -->
            <el-tab-pane label="操作日志" name="second">
              <el-table v-loading="loading" :data="list" style="width: 100%;">
                <el-table-column prop="title" label="行为" />
                <el-table-column prop="operIp" label="IP" />
                <el-table-column :show-overflow-tooltip="true" prop="operLocation" label="IP来源" />
                <el-table-column prop="os" label="系统" />
                <el-table-column prop="browser" label="浏览器" />
                <el-table-column prop="timeConsuming" label="请求耗时" align="center">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.timeConsuming <= 300">{{ scope.row.timeConsuming }}ms</el-tag>
                    <el-tag v-else-if="scope.row.timeConsuming <= 1000" type="warning">{{ scope.row.timeConsuming }}ms</el-tag>
                    <el-tag v-else type="danger">{{ scope.row.timeConsuming }}ms</el-tag>
                  </template>
                </el-table-column>
                <el-table-column
                  align="right"
                >
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="page.total>0"
                :total="page.total"
                :page.sync="page.current"
                :limit.sync="page.size"
                @pagination="getList"
              />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
    <updateEmail ref="email" :profile="user" />
    <updatePass ref="pass" />
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import user from "@/api/system/user";
import updatePass from './center/updatePass'
import updateEmail from './center/updateEmail'
import operLog from "@/api/monitor/operLog";
export default {
  name: "Profile",
  components: { updatePass,updateEmail,userAvatar, userInfo },
  data() {
    return {
      // 遮罩层
      loading: true,
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      page: {
        current: 1,
        size: 10,
        total: 0
      },
    };
  },
  created() {
    this.getUser();
    this.getList();
  },
  methods: {
    getUser() {
      user.getUserProfile().then(response => {
        this.user = response.data.user;
        this.roleGroup = response.data.roleGroup;
        this.postGroup = response.data.postGroup;
      });
    },
    /** 查询日志 */
    getList() {
      this.loading = true;
      operLog.listOperLogByUser(this.page).then( response => {
          let res = response.data
          this.list = res.records;
          this.total = res.total;
          this.loading = false;
        }
      );
    },
  }
};
</script>
